
// let path = require('path');
// let fs = require('fs');
let crypto = require('crypto');


let G = {};

// env
G.Dev = 'development';
G.Pro = 'production';
G.env = G.Dev;

// table
G.Table_User = 'user';
G.Table_Info = "info";

let emptyFun = function(){};

G.initEnv = function(){
    if(G.env === G.Pro){
        G.log = emptyFun;
        G.error = console.error.bind(console);
    }else if(G.env === G.Dev){
        G.log = console.log.bind(console);
        G.error = console.error.bind(console);
    }else{
        console.error('未设置的环境');
    }
};

G.encrypt = function(content,secret){
    let cipher = crypto.createCipher('aes192', secret);
    let enc = cipher.update(content,'utf8','hex');
    enc += cipher.final('hex');
    // console.log('enc:',enc);
    return enc;
};


G.decrypt = function(content,secret){
    G.log('解密信息.  content:',content,";secret: ",secret);
    let decipher = crypto.createDecipher('aes192',secret);
    let dec = decipher.update(content,'hex','utf8');
    dec += decipher.final('utf8');
    return dec;
};


module.exports = G;
